package main

import (
	"net/http"

	router "git.oschina.net/Ljohn/softCup/controllers"
	"git.oschina.net/Ljohn/softCup/conf"
	"fmt"
	_ "net/http/pprof"
)

func main() {
	go router.TimeRegisterGitlab()
	mux :=http.NewServeMux()
	mux.HandleFunc("/api/getProjectList", router.GetProjectList)
	mux.HandleFunc("/api/startmatch", router.SignUpOver)
	mux.HandleFunc("/api/project/branch", router.GetProjectBranch)
	mux.HandleFunc("/api/getRepertoryList", router.GetRegisterList)
	mux.HandleFunc("/api/buildProject",router.BuildProject)

	err:= http.ListenAndServe(conf.OpenPort(),middleWare(mux))
	if err !=nil{
		fmt.Println(err.Error())
	}
}

func middleWare(x http.Handler)http.Handler{
	return http.HandlerFunc(func(w http.ResponseWriter,req *http.Request){
		w.Header().Set("Access-Control-Allow-Origin", "*")
		w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Headers, APPID, Authorization, Authorization-Token")
		w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE")
		w.Header().Set("Content-Type", "application/json")
		x.ServeHTTP(w,req)
	})
}

